package com.findu.activity;

import com.example.findu.R;
import com.example.findu.R.id;
import com.example.findu.R.layout;
import com.findu.control.Public_title_dynamic;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * @ClassName: Home_More_Personal_ChangeUserName
 * @Description: TODO(修改用户的名)
 * @author hgf
 * @date 2015-11-4 下午4:51:51
 * 
 */
public class Home_More_Personal_ChangeUserName extends Activity implements
		OnClickListener {

	// 标题控制
	private Public_title_dynamic public_title;
	// 声明title布局
	private View include_view;

	// 声明意图
	private Intent intent;

	// 接收传递过来的姓氏
	private TextView change_UserName_Editext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_home__more__personal__change_user_name);

		// 初始化title
		init_title();

		// 初始化元素
		init_element();
	}

	/**
	 * 初始化需要用到的组件
	 */
	private void init_element() {
		// TODO Auto-generated method stub
		// 获取输入框
		change_UserName_Editext = (EditText) findViewById(R.id.change_Name_Editext);

		// 将传递过来的值进行设置
		intent = getIntent();

		// 取出姓氏
		String name = intent.getStringExtra("Name");
		change_UserName_Editext.setText(name);

	}

	/**
	 * 初始化title
	 */
	private void init_title() {
		// 初始化title
		include_view = findViewById(R.id.home_More_personal_ChangeUserName_include);
		public_title = new Public_title_dynamic(include_view); // 新建工具类设置布局控件

		// title详细设置
		public_title.setTextLeft("更改姓名");
		public_title.setTextView("");
		public_title.setRighttImageVisiable(false);
		public_title.setTextRight("保存");

		// 设置标题事件
		ImageView leftImage = (ImageView) include_view
				.findViewById(R.id.public_title_dynamic__liftImage);
		TextView rightText = (TextView) include_view
				.findViewById(R.id.public_title_dynamic_textViewright);

		leftImage.setOnClickListener(this);
		rightText.setOnClickListener(this);
	}

	/**
	 * 设定监听事件
	 * 
	 * @param arg0
	 */
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.public_title_dynamic__liftImage:

			finish();
			break;
		case R.id.public_title_dynamic_textViewright:
			intent = new Intent();
			// 得到输入框的值
			String input_Name = change_UserName_Editext.getText().toString()
					.trim();

			intent.putExtra("Name", input_Name);
			setResult(RESULT_OK, intent);
			finish();
			break;

		default:
			break;
		}
	}

}
